package lis.r1.wyd1;

public class Zliczanie implements Runnable {

	static int licznik;
	private static Object mutex = new Object();;

	@Override
	public void run() {

		int temp;
		
		for (int i = 0; i < 10; i++) {
			synchronized (mutex) {
				temp = licznik;
				try {
					Thread.sleep((int) (Math.random() * 200));
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				licznik = temp + 1;
				System.out.println(Thread.currentThread().getName() + ": "
						+ licznik);
			}
		}
	}

}
